package com.accp.demo.service.purchase;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.accp.demo.mapper.pruchase.IPurchaseOrderMapper;
import com.accp.demo.pojo.purchase.PurchaseInquiryDetail;
import com.accp.demo.pojo.purchase.PurchaseOrder;
import com.accp.demo.pojo.purchase.PurchaseOrderDetail;
@Service
public class PurchaseOrderService {

	@Autowired
	private IPurchaseOrderMapper iPurchaseOrderMapper;
	
	/**
	 * 新增订单的主从表
	 * @param order
	 * @return
	 */
	public void saveOrderBiz(PurchaseOrder order){
		try {
			iPurchaseOrderMapper.saveOrder(order);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 修改订单的主从表
	 * @param order
	 * @return
	 */
	public void updateOrderBiz(PurchaseOrder order){
		try {
			if (order.getPurchaseOrderDetails()!=null){
				iPurchaseOrderMapper.deleteDateil(order.getBillNo());
			}
			for (PurchaseOrderDetail i : order.getPurchaseOrderDetails()) {
				i.setBillNo(order.getBillNo());
				iPurchaseOrderMapper.saveOrderDetail(i);
			}
			iPurchaseOrderMapper.updateOrder(order);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 根据询价主表的编号查询count
	 * @param id
	 * @return
	 */
	public Integer findQueryOrderCount(String id){
		return  iPurchaseOrderMapper.queryOrderCount(id);
	}
	
	/**
	 * 逻辑删除/修改单况 主表
	 * @param id
	 * @param state
	 * @return
	 */
	public void updateOrderDelBiz(String id,Integer state,String dk){
		iPurchaseOrderMapper.updateOrderDel(id, state, dk);
	}
	/**
	 * 审核
	 * @param id
	 * @param state
	 * @return
	 */
	public void updateOrderSHBiz(String id,String date,String state,String man){
		iPurchaseOrderMapper.updateOrderSH(id, date, state, man);
	}
	
	
}
